package ca.uguu.gamelib.libgdx.concepts;

import java.util.AbstractList;
import java.util.AbstractMap;

import ca.uguu.gamelib.libgdx.globals.Constants;

import com.badlogic.gdx.math.Vector2;

public class SpriteArea {
	final public int centreX;
	final public int centreY;
	final public int width;
	final public int height;
	
	public SpriteArea(int centreX, int centreY, int width, int height){
		this.centreX = centreX;
		this.centreY = centreY;
		this.width = width;
		this.height = height;
	}
	public SpriteArea(AbstractMap<String, Object> area){
		@SuppressWarnings("unchecked")
		AbstractList<Object> centre = (AbstractList<Object>)area.get("centre");
		this.centreX = ((Integer)centre.get(0)).intValue();
		this.centreY = ((Integer)centre.get(1)).intValue();
		this.width = ((Integer)area.get("width")).intValue();
		this.height = ((Integer)area.get("height")).intValue();
	}
	
	public Vector2 getCentre(){
		return new Vector2(this.centreX, this.centreY);
	}
	public Vector2 getCentre(Vector2 spriteCentre){
		return this.getCentre(spriteCentre.x, spriteCentre.y);
	}
	public Vector2 getCentre(float spriteX, float spriteY){
		return new Vector2(spriteX + this.centreX, spriteY + this.centreY);
	}
	public Vector2 getCentre(float rotation){
		double hypotenuse = Math.sqrt(Math.pow(this.centreX, 2) + Math.pow(this.centreY, 2));
		double degree = ((Math.atan(this.centreY / (float)this.centreX)) + rotation) % Constants.CIRCLE_RADIANS;
		return new Vector2((float)(Math.cos(degree) * hypotenuse), (float)(Math.sin(degree) * hypotenuse));
	}
	public Vector2 getCentre(float spriteX, float spriteY, float rotation){
		return this.getCentre(rotation).add(spriteX, spriteY);
	}
	
	public int getTop(){
		return this.centreY - (this.height / 2);
	}
	public int getTop(int spriteY){
		return this.getTop() + spriteY;
	}
	public int getBottom(){
		return this.centreY + (this.height / 2);
	}
	public int getBottom(int spriteY){
		return this.getBottom() + spriteY;
	}
	public int getLeft(){
		return this.centreX - (this.width / 2);
	}
	public int getLeft(int spriteX){
		return this.getLeft() + spriteX;
	}
	public int getRight(){
		return this.centreX + (this.width / 2);
	}
	public int getRight(int spriteX){
		return this.getRight() + spriteX;
	}
	
	public float getAngle(){
		return 0;
	}
	public float getAngle(float rotation){
		return (this.getAngle() + rotation) % Constants.CIRCLE_RADIANS;
	}
}
